package com.feng.leetcode;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

/**
 * @author feng
 * @decrition
 * @date 2022/11/1623:15
 */
public class L775 {
    public static boolean isIdealPermutation(int[] nums) {
        List<Integer> overall = new ArrayList<>();
        int all = 0;
        List<Integer> local = new ArrayList<>();
        TreeMap<Integer, Integer> map = new TreeMap<>();
        /*for (int i = nums.length - 1; i > 0; i--) {
            map.put(nums[i], map.getOrDefault(nums[i], 0) + 1);
            int j = i - 1;
            if (nums[j] > nums[i]) {
                local.add(j);
            }
            for (Integer integer : map.keySet()) {
                if (nums[j] > integer) {
                    all += map.get(integer);
                } else {
                    break;
                }
            }
        }*/
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] > nums[j]) {
                    if (i + 1 == j) {
                        overall.add(i);
                        local.add(i);
                    } else {
                        return false;
                    }
                }
            }
        }

        return overall.size() == local.size();
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1, 0, 2};
        isIdealPermutation(nums);
    }
}
